package com.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {
    //强制登录拦截器

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object login = request.getSession().getAttribute("login");
        if(login !=null){
            return true;
        }
        //若没有登录标识，则不放行，重定向到登录页面
        response.sendRedirect(request.getContextPath()+"/front/login.jsp");
        return false;
    }
}


